package JUC.wn_syn_vlo;

public class interrupt中断 {
    public static void main(String[] args) throws Exception {
        Thread t1=new Thread(){
            @Override
            public void run(){
                while(true){
                    //判断当前线程是否被中断
                    if (this.isInterrupted()){
                        System.out.println("线程中断");
                        try {
                            Thread.sleep(3000);
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        }
                        break;
                    }
                }

                System.out.println("已跳出循环,线程中断!");
            }
        };
        t1.start();
        Thread.sleep(2000);
        t1.interrupt();

        /**
         * 输出结果:
         线程中断
         已跳出循环,线程中断!
         */
    }
}